package org.teremail.smtp.commands;

import java.util.List;

import org.teremail.smtp.SMTPCommandFactory;
import org.teremail.smtp.SMTPSession;

/**
 * Simple (older) hello (HELO) implementation.
 * 
 * @author Michael Barker
 *
 */
public class HELOCommand extends SMTPCommand {

    public HELOCommand(List<String> parameters) {
        super("HELO", parameters);
    }
    
    final static String MSG_250 = "250 %s welcomes (%s)";
    final static String MSG_501_NODOMAIN = "501 Domain not specified in HELO";

    @Override
    public void process(SMTPSession session) {
        
        if (getParameters().size() == 0) {
            session.write(MSG_501_NODOMAIN);
        } else {
            String hostName = session.getHostName();
            String clientName = getParameters().get(0);
            session.write(String.format(MSG_250, hostName, clientName));
        }
    }


    public static final SMTPCommandFactory FACTORY = new SMTPCommandFactory() {

        public SMTPCommand create(List<String> parameters) {
            return new HELOCommand(parameters);
        }
        
    };
    
}
